import { Leafer } from 'leafer-ui'
import { IToolConfig } from '../types'
import { BaseTool } from './BaseTool'

export class ToolManager {
  private currentTool: BaseTool | null = null
  private tools = new Map<string, BaseTool>()

  constructor(private app: Leafer, private config: IToolConfig) {}

  // 注册工具
  registerTool(tool: BaseTool) {
    this.tools.set(tool.name, tool)
  }

  // 切换工具
  switchTool(toolName: string) {
    if (this.currentTool?.name === toolName) return
    this.currentTool?.deactivate()
    const tool = this.tools.get(toolName)
    if (tool) {
      this.currentTool = tool
      tool.activate()
    }
  }

  // 获取当前工具
  getCurrentTool() {
    return this.currentTool
  }
}